package cn.iocoder.yudao.module.pm.controller.app.qcrecords;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.pm.controller.app.qcrecords.vo.AppQcRecordsPageReqVO;
import cn.iocoder.yudao.module.pm.controller.app.qcrecords.vo.AppQcRecordsRespVO;
import cn.iocoder.yudao.module.pm.controller.app.qcrecords.vo.AppQcRecordsSaveReqVO;
import cn.iocoder.yudao.module.pm.service.qcrecords.QcRecordsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 过程管理-速冷处理记录")
@RestController
@RequestMapping("/pplan/pm/qc-records")
@Validated
public class AppQcRecordsController {

    @Resource
    private QcRecordsService qcRecordsService;

    @PostMapping("/create")
    @Operation(summary = "创建过程管理-速冷处理记录")
    @PreAuthorize("@ss.hasPermission('pm:qc-records:create')")
    public CommonResult<Long> createQcRecords(@Valid @RequestBody AppQcRecordsSaveReqVO createReqVO) {
        return success(qcRecordsService.appCreateQcRecords(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新过程管理-速冷处理记录")
    public CommonResult<Boolean> updateQcRecords(@Valid @RequestBody AppQcRecordsSaveReqVO updateReqVO) {
        qcRecordsService.appUpdateQcRecords(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除过程管理-速冷处理记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('pm:qc-records:delete')")
    public CommonResult<Boolean> deleteQcRecords(@RequestParam("id") Long id) {
        qcRecordsService.appDeleteQcRecords(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得过程管理-速冷处理记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppQcRecordsRespVO> getQcRecords(@RequestParam("id") Long id) {
        AppQcRecordsRespVO qcRecords = qcRecordsService.appGetQcRecords(id);
        return success(qcRecords);
    }

    @GetMapping("/page")
    @Operation(summary = "获得过程管理-速冷处理记录分页")
    public CommonResult<PageResult<AppQcRecordsRespVO>> getQcRecordsPage(@Valid AppQcRecordsPageReqVO pageReqVO) {
        PageResult<AppQcRecordsRespVO> pageResult = qcRecordsService.appGetQcRecordsPage(pageReqVO);
        return success(pageResult);
    }

}